package net.cloudcodex.client.campaign.view.panel;

import java.util.Date;

import net.cloudcodex.client.campaign.view.CampaignsView.Message;
import net.cloudcodex.client.widgets.ToggleButtonGroup;
import net.cloudcodex.shared.dto.home.CampaignSummaryDTO;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.ToggleButton;

public class CampaignPanel extends FlowPanel {

	public static final String CHARACTERS_LIST = "charactersList";
	public static final String STORY_BOARD = "storyBoard";
	public static final String CAMPAIGN_CONFIG = "campaignConfig";
	public static final String NOTIFICATION = "notification";
	private CampaignSummaryDTO campaignSummary;
	private Message message;
	private final NotificationListPanel notificationListPanel;


	private final HorizontalPanel buttonPanel = new HorizontalPanel();

	private final SimplePanel contentPanel = new SimplePanel();

	private ToggleButtonGroup toggleButtonGroup;

	private ToggleButton notificationButton;

	private ToggleButton campaignConfigButton;

	private ToggleButton storyBoardButton;

	private ToggleButton charactersListButton;

	public CampaignPanel(Message message) {
		this.message = message;
		notificationListPanel = new NotificationListPanel(message.getNoMessages(),message.getMessagesTitle());
		initToggleButtonGroup();
		this.add(notificationListPanel);
		this.add(toggleButtonGroup);
		contentPanel.setHeight("100%");
		this.add(contentPanel);
	}

	/**
	 * @param message
	 */
	private void initToggleButtonGroup() {
		toggleButtonGroup = new ToggleButtonGroup();
		notificationButton = new ToggleButton(message.getNotificationButton());
		notificationButton.setTitle(NOTIFICATION);
		campaignConfigButton = new ToggleButton(
				message.getCampaignConfigButton());
		campaignConfigButton.setTitle(CAMPAIGN_CONFIG);
		storyBoardButton = new ToggleButton(message.getStoryBoardButton());
		storyBoardButton.setTitle(STORY_BOARD);
		charactersListButton = new ToggleButton(
				message.getCharactersListButton());
		charactersListButton.setTitle(CHARACTERS_LIST);
		toggleButtonGroup.addButton(campaignConfigButton);
		toggleButtonGroup.addButton(storyBoardButton);
		toggleButtonGroup.addButton(charactersListButton);
		toggleButtonGroup.addButton(notificationButton);
	}

	public void addNotification(String notification, Date notificationDate) {
		notificationListPanel.addNotification(notification, notificationDate);
	}

	public void refreshNotification() {
		notificationListPanel.refresh();
	}

	public void addCampaignName(String name) {
		notificationListPanel.addCampaignName(name);
	}

	public void refreshContent(IsWidget view) {
		this.contentPanel.clear();
		this.contentPanel.add(view);
	}
	public CampaignSummaryDTO getCampaignSummary() {
		return campaignSummary;
	}


	public HasClickHandlers getNotificationListBox() {
		return this.notificationListPanel.getNotificationListBox();
	}

	public HasClickHandlers getToggleButtonGroup() {
		return this.toggleButtonGroup;
	}

	public void setSelectedButton(String selectedToggleButton) {
		this.toggleButtonGroup.setSelectedButton(selectedToggleButton);

	}

}
